package com.shujia.hbase.javacode;

import java.io.BufferedReader;
import java.io.FileReader;

public class JavaApi {
    public static void main(String[] args) throws Exception {

        Long sId = 1500100009L;

        /**
         * 同构学号查询学生信息
         * 1、查询索引表
         * 2、查询数据表
         */

        String fileName = "";

        //1、根据索引表判断学号在哪一个文件中

        BufferedReader indexReader = new BufferedReader(new FileReader("java/data/hbase/index"));

        String index;
        while ((index = indexReader.readLine()) != null) {

            String[] split = index.split(",");
            String fileIndex = split[0];
            long startKey = Long.parseLong(split[1]);
            long endKey = Long.parseLong(split[2]);

            if (sId >= startKey && sId <= endKey) {
                fileName = "java/data/hbase/data/" + fileIndex;
            }
        }

        if (fileName.equals("")) {
            System.out.println("学号：" + sId + " 不存在");
            return;
        }

        /**
         * 查询数据表
         *
         */

        BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));

        String line;
        while ((line = bufferedReader.readLine()) != null) {

            /**
             * 判断是不是这个学生
             *
             */
            long id = Long.parseLong(line.split(",")[0]);

            if (id == sId) {
                System.out.println(line);
                break;
            }
        }


    }
}
